﻿using System.IO;
using System.Text;

namespace Z.GenerateIconProject.WinForm
{
    public partial class IconLibraryHelper
    {
        public static string GetProjectEmbeddedText(ProjectConfig project)
        {
            var sb = new StringBuilder();

            foreach (IconConfig item in project.IconConfigs)
            {
                sb.Append(GetProjectEmbeddedText(project, item));
            }

            return sb.ToString();
        }

        public static string GetProjectEmbeddedText(ProjectConfig project, IconConfig config)
        {
            const string template = "    <EmbeddedResource Include=\"@(Model.IconSize)\\@(Model.FileName)\" />";
            var sb = new StringBuilder();

            foreach (FileInfo file in config.SourcePath.ToDirectoryInfo().GetFiles())
            {
                string s = template;
                s = s.Replace("@(Model.IconSize)", config.DestinationName);
                s = s.Replace("@(Model.FileName)", file.Name);

                sb.AppendLine(s);
            }
            return sb.ToString();
        }
    }
}